/**
 * Created by win10 on 2019/4/30.
 */
var client = require('./../redis_client');
var gameConfig = require("./../config/gameConfig");
var log = require("./../../util/loginfo").getInstand;

var redis_bet_key = "game_serverId-" + gameConfig.serverId;
var redis_bet_list_key = "game_serverId-" + gameConfig.serverId + "-";

//获得重置下注数组
exports.init_bet_list = function init_bet_list() {
    //清除数组
    client.del(redis_bet_key);
};

//下注
exports.save_bet = function save_bet(userId, bet_info) {
    client.rpush(redis_bet_list_key + userId, JSON.stringify(bet_info));
};

exports.del_bet = function del_bet(userId) {
    try {
        client.del(redis_bet_list_key + userId);
    } catch (error) {
        log.err(error);
    }
};

//获取下注记录
exports.get_bet_list = function get_bet_list(userId) {
    return new Promise((resolve, reject) => {
        log.info("lrange " + (redis_bet_list_key + userId))
        client.lrange(redis_bet_list_key + userId, 0., -1, function (err, lists) {
            var result=[];
            if(!err){
                for(var i in lists){
                    result.push(JSON.parse(lists[i]));
                    log.info("bet info " + lists[i]);
                }
                log.info("get bet list result " + result);
                resolve(result);
            } else {
                log.err(err);
            }
        });
    })
};




